﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace 信息记录系统
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                MessageBox.Show("客户名称不能为空！");
                return;
            }
            if (textBox2.Text == string.Empty)
            {
                MessageBox.Show("设备名称不能为空");
                return;
            }
            if (textBox3.Text == string.Empty)
            {
                MessageBox.Show("型号不能为空");
                return;
            }
            if (textBox4.Text == string.Empty)
            {
                MessageBox.Show("序列号不能为空");
                return;
            }
            if (textBox5.Text == string.Empty)
            {
                MessageBox.Show("管理地址不能为空");
                return;
            }
            if (textBox6.Text == string.Empty)
            {
                MessageBox.Show("管理账号不能为空");
                return;
            }
            if (textBox7.Text == string.Empty)
            {
                MessageBox.Show("维保情况不能为空");
                return;
            }
            if (textBox8.Text == string.Empty)
            {
                MessageBox.Show("备注不能为空");
                return;
            }
            if (textBox13.Text == string.Empty)
            {
                MessageBox.Show("管理密码不能为空");
                return;
            }
            if (textBox14.Text == string.Empty)
            {
                MessageBox.Show("授权到期时间不能为空");
                return;
            }
            if (textBox15.Text == string.Empty)
            {
                MessageBox.Show("备注不能为空");
                return;
            }
            string connStr = "#";
            //创建 SqlConnection的实例
            MySqlConnection conn = null;
            try
            {
                conn = new MySqlConnection(connStr);
                //打开数据库连接
                conn.Open();
                //string sql = "insert into sys_user_data(customername,serviceaddress,systemversion,webversion,webname,webpath,webport,langues,sqltype,sqlpath,protect,nykeep,servicepurpose,serviesname,businessname,sqlport,servicestime,nowhy,uppertimes,clostimes,stautimes,notie,datapasswd) values('{0}','{1}')";
                string sql = "insert into sys_security_data_carry(`number-id`,`equipment-name`,model,`number-serial`,`admin-address`,username,maintenance,notie,password,`auto-times`,`type`) values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}')";
                //serviceaddress, systemversion, webversion, webcorepath, webpath, webname, langues, webport, sqltype, sqlpath, sqlport, servicestime, nowhy, stautimes, clostimes, notie, servicename, businessname, servicepurpose, nykeep, protect, customername, uppertimes, datapasswd
                /*(`number-id`, `equipment-name`, `type`, model, `number-serial`, `auto-times`, `admin-address`, username, password, maintenance, notie
                1：序号   number-id,equipment-name,model,number-serial,admin-address,username,maintenance,notie,password,auto-times,type
                2：设备名称
                3：型号
                4：序列号
                5：管理地址
                6：管理账号
                7：维保情况
                8：备注
                13：管理密码
                14：授权到期时间
                15：类型
                 */
                //填充SQL语句
                // sql = string.Format(sql, textBox1.Text, textBox2.Text, textBox3.Text);
                sql = string.Format(sql, textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox13.Text, textBox14.Text, textBox15.Text);
                //创建SqlCommand对象
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                //执行SQL语句
                int returnvalue = cmd.ExecuteNonQuery();
                //判断SQL语句是否执行成功
                if (returnvalue != -1)
                {
                    MessageBox.Show("数据添加成功！");
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误提示：" + ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    //关闭数据库连接
                    conn.Close();
                }
            }
        }
    }
}
